/*
 * TemperatureView.cpp
 *
 *  Created on: Nov 27, 2010
 *      Author: Ben
 */

#include "TemperatureView.h"

#include <avr/pgmspace.h>

#include <Observer/Observable.h>
#include <Flash/Flash.h>

#include "View.h"
#include "Thermostat.h"
#include "ButtonPad.h"


TemperatureView::TemperatureView(LCD *lcd, Thermostat *therm, ButtonPad* buttonPad) : View(lcd) {
  this->thermostat = therm;
  this->buttonPad = buttonPad;

}

void TemperatureView::update(Observable *o) {
  if (this->isActive) {
    if (o == buttonPad) {
      if (((ButtonPad*)o)->read() == BUTTON_UP) {
        thermostat->setTargetTemp(thermostat->getTargetTemp()+1);
      }
      else if (((ButtonPad*)o)->read() == BUTTON_DOWN) {
        thermostat->setTargetTemp(thermostat->getTargetTemp()-1);
      }
    }
    lcd->setCursorLine1();
    lcd->print(F("Set Temp: "));
    lcd->print(thermostat->getTargetTemp());
    lcd->setCursorLine2();
    lcd->print(F("Real Temp: "));
    lcd->print(thermostat->getCurrentTemp());
  }
}


